<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>修改密码</title>
    <link rel="stylesheet" href="../layuiadmin/layui/css/layui.css" media="all">
</head>

<body>
    <div class="layui-form" lay-filter="layuiadmin-form-useradmin" id="layuiadmin-form-useradmin"
        style="padding: 20px 0 0 0;">
        <div class="layui-form-item">
            <label class="layui-form-label">原密码</label>
            <div class="layui-input-inline">
                <input type="password" name="userPass1" lay-verify="required" placeholder="请输入原密码" autocomplete="off"
                    class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">新密码</label>
            <div class="layui-input-inline">
                <input type="password" name="userPass2" lay-verify="required" placeholder="请输入新密码" autocomplete="off"
                    class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">确认密码</label>
            <div class="layui-input-inline">
                <input type="password" name="userPass3" lay-verify="required" placeholder="请再次输入新密码" autocomplete="off"
                    class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit="" lay-submit lay-filter="edit-submit">确认</button>
            </div>
        </div>
    </div>
    <script src="../layuiadmin/layui/layui.js"></script>
    <script>
        layui.use(['form'], function () {
            var $ = layui.$
                , form = layui.form;
            //监听搜索
            form.on('submit(edit-submit)', function (data) {
                var field = data.field;
                if (!field.userPass1) {
                    layer.msg('请输入原密码', { icon: 5 });
                    return;
                }
                if (!field.userPass2) {
                    layer.msg('请输入新密码', { icon: 5 });
                    return;
                }
                //首先盘点两次密码是否相等
                if (field.userPass2 != field.userPass3) {
                    layer.msg('确认密码与新密码不同', { icon: 5 });
                    return;
                }
                delete field.password3;
                $.ajax({
                    url: `passwordEdit`
                    , type: 'post'
                    , data: JSON.stringify(field)
                    , contentType: "application/json"
                    , success: function (data) {
                        if (!data.code) {
                            layer.msg('修改成功', { icon: 6 });
                        }
                        else
                            layer.msg(data.msg, { icon: 5 });
                    }
                    , error: function (data) {
                        layer.msg(data, { icon: 5 });
                    }
                });

            });
        });
    </script>
</body>

</html>